{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-05 17:46:20.630\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m37\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-06-05 17:46:20,689\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-06-05 17:46:20,709\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "你好！有什么可以帮助你的吗？\n"
     ]
    }
   ],
   "source": [
    "import byzerllm\n",
    "byzerllm.connect_cluster()\n",
    "llm = byzerllm.ByzerLLM()\n",
    "llm.setup_default_model_name(\"deepseek_chat\")\n",
    "v = llm.chat_oai(conversations=\"你好\")\n",
    "print(llm.require_template(\"deepseek_chat\"))\n",
    "print(v[0].output)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-07 15:00:16.906\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m37\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-06-07 15:00:16,953\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-06-07 15:00:16,970\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[33m(raylet)\u001b[0m Jun 07, 2024 3:26:32 PM org.apache.lucene.internal.vectorization.PanamaVectorizationProvider <init>\n",
      "\u001b[33m(raylet)\u001b[0m INFO: Java vector incubator API enabled; uses preferredBitSize=256\n",
      "\u001b[33m(raylet)\u001b[0m WARNING: Using incubator modules: jdk.incubator.vector\n",
      "\u001b[33m(raylet)\u001b[0m Jun 10, 2024 10:21:29 PM org.apache.lucene.internal.vectorization.PanamaVectorizationProvider <init>\n",
      "\u001b[33m(raylet)\u001b[0m INFO: Java vector incubator API enabled; uses preferredBitSize=256\n",
      "\u001b[33m(raylet)\u001b[0m WARNING: Using incubator modules: jdk.incubator.vector\n"
     ]
    }
   ],
   "source": [
    "import ray\n",
    "import ray.util.client\n",
    "import byzerllm\n",
    "\n",
    "# byzerllm.connect_cluster(address=\"ray://127.0.0.1:10001\")\n",
    "\n",
    "# byzerllm.connect_cluster(address=\"ray://127.0.0.1:10001\")\n",
    "byzerllm.connect_cluster()\n",
    "\n",
    "def is_ray_in_client_mode():\n",
    "    if ray.is_initialized() and ray.util.client.ray.is_connected():\n",
    "        return True\n",
    "    return False\n",
    "\n",
    "print(is_ray_in_client_mode())\n",
    "# v = ray.get_actor(\"ByzerRetrievalProxy\")\n",
    "# # print(v)\n",
    "# # ray.kill(v)\n",
    "# retrieival = byzerllm.ByzerRetrieval(pure_client=False)\n",
    "# retrieival.launch_gateway()\n",
    "\n",
    "# retrieival.cluster_info(name=\"byzerai_store\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
